﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataMappers;
using ConcreteMappersAndObjects.DomainObjects;

namespace ConcreteMappersAndObjects.Mappers
{
    public class ExamSeasonDataMapper : AbstractDataMapper<int, ExamSeason>
    {
        protected override int GetKeyFrom(System.Data.SqlClient.SqlDataReader sdr)
        {
            return sdr.GetInt32(0);
        }

        protected override string DoGetAllStatement()
        {
            return "select ID, Description, StartSeason, EndSeason from ExamSeason";
        }

        protected override string DoGetFindStatement()
        {
            return DoGetAllStatement() + " where ID = @ID";
        }

        protected override void BindFindStatement(System.Data.SqlClient.SqlCommand cmd, int key)
        {
            cmd.Parameters.AddWithValue("@ID", key);
        }

        protected override ExamSeason DoLoad(System.Data.SqlClient.SqlDataReader sdr)
        {
            return new ExamSeason(sdr.GetInt32(0), sdr.GetString(1), sdr.GetDateTime(2), sdr.GetDateTime(3));
        }

        protected override string GetUpdateCommand()
        {
            return "update ExamSeason set Description = @Description, StartSeason = @StartSeason, EndSeason = @EndSeason where ID = @ID";
        }

        protected override void DoBindUpdate(System.Data.SqlClient.SqlCommand cmd, ExamSeason t)
        {
            cmd.Parameters.AddWithValue("@Description", t.Description);
            cmd.Parameters.AddWithValue("@StartSeason", t.StartSeason);
            cmd.Parameters.AddWithValue("@EndSeason", t.EndSeason);
            cmd.Parameters.AddWithValue("@ID", t.ID);
        }

        protected override string GetInsertCommand()
        {
            return "ExamSeasonInsert";
        }

        protected override void DoBindInsert(System.Data.SqlClient.SqlCommand cmd, ExamSeason t)
        {
            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@Description", t.Description);
            cmd.Parameters.AddWithValue("@StartSeason", t.StartSeason);
            cmd.Parameters.AddWithValue("@EndSeason", t.EndSeason);
        }

        protected override string GetRemoveCommand()
        {
            return "delete ExamSeason where ID = @ID";
        }

        protected override void DoBindRemove(System.Data.SqlClient.SqlCommand cmd, ExamSeason t)
        {
            cmd.Parameters.AddWithValue("@ID", t.ID);
        }

        protected override void FinishUpdateObject(ExamSeason t)
        {
            
        }

        protected override void FinishNewObject(ExamSeason t, object id)
        {
            t.ID = Convert.ToInt32(id);
        }

        protected override void FinishDeleteObject(ExamSeason t)
        {
            
        }
    }
}
